
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InitializeBankAsset] 
	@Game_ID numeric(10,0) = null
AS
BEGIN 
	DECLARE @Player_ID int
	SET @Player_ID = (SELECT pe.[Player_ID] 
		FROM [dbo].[Player] p JOIN [dbo].[PlayerEnrollment] pe ON (p.player_id = pe.player_id and p.isActive = 'Y' and p.[type]= 'Bank') 
		WHERE pe.IsActive = 'Y'
			and pe.[Game_ID] = @Game_ID)
	
	INSERT INTO [dbo].[PlayerAsset]([Game_ID],[Player_ID],[AssetType],[Land_ID],[GameCard_ID],[Currency]) VALUES(@Game_ID,@Player_ID,'Cash',NULL,NULL,10000)
	
	DECLARE @ID int
	DECLARE IDs CURSOR LOCAL FOR 
		SELECT Land_ID FROM [dbo].[Land] l WHERE l.IsActive = 'Y' and l.[Type] in ('U','T','L') Order By Position

	OPEN IDs
	FETCH NEXT FROM IDs into @ID
	WHILE @@FETCH_STATUS = 0
	BEGIN
		INSERT INTO [dbo].[PlayerAsset]([Game_ID],[Player_ID],[AssetType],[Land_ID],[GameCard_ID],[Currency]) VALUES(@Game_ID,@Player_ID,'Fixed',@ID,NULL,0)

		FETCH NEXT FROM IDs into @ID
	END

	CLOSE IDs
	DEALLOCATE IDs

END

-- [dbo].[InitializeBankAsset] 1